package com.example.server.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.server.bean.Employee;
import com.example.server.bean.Salary;
import com.example.server.service.IEmployeeService;
import com.example.server.service.ISalaryService;
import com.example.server.util.PageRespBean;
import com.example.server.util.RespBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ProjectName: yeb
 * Author: 别怿言
 * Date: 2023-02-11 23:56
 * Description：员工张涛接口
 */
@Api(tags = "SalarySobCfg")
@RestController
@RequestMapping("/salary/sobcfg")
public class SalarySobCfgController {

    @Autowired
    private ISalaryService salaryService;
    @Autowired
    private IEmployeeService employeeService;

    @ApiOperation(value = "查询所有工资账套")
    @GetMapping("/salaries")
    public List<Salary> getAllSalaries(){
        return salaryService.list();
    }

    @ApiOperation(value = "查询员工工资账套（分页）")
    @GetMapping("/")
    public PageRespBean getSalariesByPage(@RequestParam(defaultValue = "1") Integer currentPage,
                                          @RequestParam(defaultValue = "10") Integer size){
        return employeeService.getSalariesByPage(currentPage,size);
    }

    @ApiOperation(value = "更新员工账套")
    @PutMapping("/salaries")
    public RespBean updateEmployeeSalary(Integer eid,Integer sid){
        if(employeeService.update(new UpdateWrapper<Employee>().set("salaryId",sid).eq("id",eid))){
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

}
